package com.group01.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.github.yulichang.base.MPJBaseMapper;
import com.group01.pojo.ShopCar;
import com.group01.vo.ShopCar.ShopCarGetInfoVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
* @author 19559
* @description 针对表【es_shopCar(购物车表)】的数据库操作Mapper
* @createDate 2024-06-23 08:45:12
* @Entity com.group01.pojo.ShopCar
*/
public interface ShopCarMapper extends MPJBaseMapper<ShopCar> {
    /**
     * 查询当前用户购物车列表
     */
    List<ShopCarGetInfoVO> getShopCarInfoList(@Param(Constants.WRAPPER) Wrapper<ShopCarGetInfoVO> wrapper);

    /**
     * 更新商品数量
     */
    @Update("update es_shopCar set num = num + #{num} where user_id = #{userId} and goods_id = #{goodsId}")
    void updateShopCarNum(@Param("userId") Integer userId,@Param("goodsId") Integer shopCarId, @Param("num") Integer num);

    /**
     * 检查购物车id
     */
    @Select("select count(*) from es_shopCar where id = #{id}")
    Integer checkShopCarId(Integer id);

    /**
     * 根据主键加购商品数量
     */
    @Update("update es_shopCar set num = #{num} where id = #{id}")
    void updateShopCarNumByPrimaryKey(@Param("id") Integer id, @Param("num") Integer num);
}




